export default {
    namespaced: true,
    state: () => ({
        token: sessionStorage.getItem('setToken') || '',
        followList: JSON.parse(localStorage.getItem('followList')||'[]') //用户关注列表
    }),
    mutations: {
        //  token持久化
        getlocalStorage(state) {
            sessionStorage.setItem('setToken', state.token)
        },
        getToken(state, val) {
            state.token = val
            this.commit('m_user/getlocalStorage')
        },
        delToken(state) {
            state.token = ''
            this.commit('m_user/getlocalStorage')
            console.log(state.token);
        },
        // 添加关注用户
        addfollowList(state,actorInfo) {
            console.log(actorInfo);
            const userResult=state.followList.find(item=>item.name===actorInfo.name)
            if(!userResult){
                 actorInfo.alreadyfollowed=true
                state.followList.push(actorInfo)
            }else{
               
            }
            localStorage.setItem('followList', JSON.stringify(state.followList))
        },
        delfollowList(state,actorInfo){
              state.followList= state.followList.filter(item=>!actorInfo)
               localStorage.setItem('followList', JSON.stringify(state.followList))
        }
    },
    getters: {}
}